package businessdomain.generator.hibernate;

import com.google.inject.Inject;
import com.ldh.mod4j.businessdomain.BusinessDomainDslInjectorProvider;
import com.ldh.mod4j.businessdomain.businessDomainDsl.BusinessClass;
import com.ldh.mod4j.businessdomain.businessDomainDsl.BusinessDomainModel;
import com.ldh.mod4j.businessdomain.generator.hibernate.DaoInterfaceBase;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtext.junit4.InjectWith;
import org.eclipse.xtext.junit4.XtextRunner;
import org.eclipse.xtext.junit4.util.ParseHelper;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mod4j.dslcommon.generator.helpers.ProjectProperties;

@SuppressWarnings("all")
@InjectWith(BusinessDomainDslInjectorProvider.class)
@RunWith(XtextRunner.class)
public class TestDaoInterfaceBase {
  
  @Inject
  private ParseHelper<BusinessDomainModel> parser;
  
  @Inject
  private DaoInterfaceBase daoInterfaceBaes;
  
  private String modelText;
  
  private BusinessDomainModel model;
  
  @Before
  public void setUp() throws Exception {
    {
      this.modelText = "\n\t\t\t\"The RecordShop domain model\"\n\t\t\tdomain recordshopcore;\n\t\t\t           \n\t\t\t/*        \n\t\t\t * Remarks...                    \n\t\t\t */\n\t\t\t      \n\t\t\t\"A Person represents a legal person.\"  \n\t\t\tclass Person [ \n\t\t\t    \"First name of the person.\"   \n\t\t\t    string firstName; \n\t\t\t    \"Last name of the person.\"    \n\t\t\t    string lastName;   \n\t\t\t    datetime birthDate;\n\t\t\t    \"The age of this person in years, derived from birthDate\"\n\t\t\t    integer age derived;      \n\t\t\t    \"Number of ears (we allow Vulcans in this system).\"  \n\t\t\t    integer numberOfEars default 2 min 0 max 4;   \n\t\t\t    \"Gender\"       \n\t\t\t    SexeEnum sexe default MALE nullable;    \n\t\t\t\n\t\t\t    rules [   \n\t\t\t        \"The combination of first- and last name of a person must be unique\"\n\t\t\t        unique fullName [firstName, lastName]\n\t\t\t    ]  \n\t\t\t]\n\t\t\tassociation Person personFrom one <-> many Relation relationsFrom;\n\t\t\tassociation Person personTo one <-> many Relation relationsTo;\n\t\t\t\n\t\t\tclass Relation [\n\t\t\t    string name;\n\t\t\t    datetime since nullable;\n\t\t\t    datetime ended nullable;\n\t\t\t]\n\t\t\t\n\t\t\tclass Address [\n\t\t\t    string streetName;\n\t\t\t    string houseNumber;\n\t\t\t    string zipcode regexp \"\\\\d{5}(-\\\\d{4})?\";\n\t\t\t    string city;  \n\t\t\t]\n\t\t\t\n\t\t\t\"A Customer represents a Person who orders from the RecordShop.\"\n\t\t\tclass Customer inherits Person [\n\t\t\t    integer customerNr;  \n\t\t\t    string username minlength 3 maxlength 10 nullable ;\n\t\t\t    string emailAddress regexp \"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,4}$\" nullable;\n\t\t\t    boolean blackListed default false nullable;\n\t\t\t    integer discountPercentage default 0 min 0 max 100 ;\n\t\t\t    \n\t\t\t    rules [  \n\t\t\t        \"The customerNr must be unique\" \n\t\t\t        unique uniqueCustomerNr [customerNr]\n\t\t\t        \"If Customer has one ear, he/she get a discount of 50 percent.\"  \n\t\t\t        OneEarDiscount;  \n\t\t\t        \"Just another rule\"\n\t\t\t        AnotherRule; \n\t\t\t    ]\n\t\t\t]\n\t\t\t\n\t\t\t\"An artist is a Person who has had a role in producing a Record\"\n\t\t\tclass Artist inherits Person [\n\t\t\t    string artistName;\n\t\t\t    string biography maxlength 32000 nullable;\n\t\t\t]\n\t\t\t\n\t\t\t\"A Record is a representation of a physical medium containing one or more musical compositions.\"\n\t\t\tclass Record [\n\t\t\t    string asin;\n\t\t\t    string title default \"Title unknown\";\n\t\t\t    integer mediumCode default 111 ;\n\t\t\t    decimal price precision 10 scale 2;\n\t\t\t    RecordTypeEnum type;\n\t\t\t]\n\t\t\t\n\t\t\t\"An Order represents the agreement between a Customer and the RecordShop about one or more purchased Records.\"\n\t\t\tclass Order [\n\t\t\t\t\"A number to identify the Order\"\n\t\t\t    string    orderNumber;\n\t\t\t    \"The date on which the order has been placed\"\n\t\t\t    datetime  orderDate default \"2009-01-01\" nullable;\n\t\t\t    datetime  deliveryDateTime  nullable;\n\t\t\t    integer   discountPercentage min 01 max 100 nullable ;\n\t\t\t    \"The total amount of the Order. Its value is derived from the summation of the OrderLine amounts\"\n\t\t\t    decimal   totalAmount nullable derived; \n\t\t\t    \n\t\t\t    rules [\n\t\t\t        \"The orderNumber of a Order must be unique \"\n\t\t\t        unique uniqueOrderNumber [orderNumber]\n\t\t\t          \n\t\t\t        \"The deliveryDate may not precede orderDate\"\n\t\t\t        OrderDateBeforeDeliveryDate;   \n\t\t\t    ]\n\t\t\t]\n\t\t\t\n\t\t\tclass OrderLine [ \n\t\t\t    integer lineNumber min 01 max 50;\n\t\t\t    integer quantity default 1;\n\t\t\t    string description;\n\t\t\t    decimal lineAmount derived;\n\t\t\t    rules [\n\t\t\t    \tCheckProductMinimumQuantity;\n\t\t\t    ] \n\t\t\t]\n\t\t\t\n\t\t\tclass Product [\n\t\t\t\tstring productNumber;\n\t\t\t\tdecimal price;\n\t\t\t\tboolean inStock default false;\n\t\t\t\tboolean orderable;\n\t\t\t\tinteger minimalQuantity default 1;\n\t\t\t]\n\t\t\t\n\t\t\t\"Sexe enumeration.\"\n\t\t\tenumeration SexeEnum [\n\t\t\t    FEMALE = 2;\n\t\t\t    MALE = 3;\n\t\t\t]\n\t\t\t\n\t\t\tenumeration RecordTypeEnum [\n\t\t\t    LP = 2;\n\t\t\t    CD = 3;\n\t\t\t    DVD = 4;\n\t\t\t    BLUERAY = 5;\n\t\t\t]\n\t\t\t\n\t\t\t\"One 2 Many bidirectional: A customer has a number of orders.\" \n\t\t\tassociation Customer customer one <-> many Order orders ;\n\t\t\t\n\t\t\t\"One 2 Many unidirectional: An order consists of an ordered list of orderLines.\n\t\t\tThis is a typical composite relation: An orderLine must be attached to an existing order. \n\t\t\tWhen an order is deleted, also a cascading delete of all the orderLines attached to it must be performed.\"\n\t\t\tassociation Order order one -> many OrderLine orderLines ordered ;\n\t\t\t\n\t\t\t\"One 2 One bidirectional: An orderLine contains a product.\"\n\t\t\tassociation OrderLine orderLine  one <-> one Product product ;\n\t\t\t\n\t\t\t\"Many to One bidirectional: A record is sold as a product.\"\n\t\t\tassociation Record  records many <-> one Product product ;\n\t\t\t\n\t\t\t\"Many to Many bidirectional: Records have been made by zero or more contributors.\"\n\t\t\tassociation Record records many <-> many Artist contributors ;\n\t\t\t\n\t\t\t\"Many to Many unidirectional: Products have been bought by zero or more buyers.\"\n\t\t\tassociation Product products many -> many Customer buyers ;\n\t\t\t\n\t\t\t\"Many to One unidirectional: Customers have one invoiceAddress\" \n\t\t\tassociation Customer customers many -> one Address invoiceAddress;\n\t\t\t\n\t\t\tassociation Address homeAddress one <-> many Person persons;\n\t\t\t\n\t\t\tassociation Customer customers many -> many Artist idols;\n\t\t\t\"Tests\"\n\t\t\tassociation Person person one -> many Artist relatedTo ; \n\t\t";
      BusinessDomainModel _parse = this.parser.parse(this.modelText);
      this.model = _parse;
      ProjectProperties.setProperties("com.ldh");
    }
  }
  
  @Test
  public void testParseDomainModel() throws Exception {
    {
      BusinessDomainModel _parse = this.parser.parse(this.modelText);
      final BusinessDomainModel model = _parse;
      InputOutput.<String>println("*** testParseDomainModel ****");
      String _name = model.getName();
      String _operator_plus = StringExtensions.operator_plus("--- Model name: ", _name);
      InputOutput.<String>println(_operator_plus);
    }
  }
  
  @Test
  public void testGenerateCode() {
    EList<BusinessClass> _types = this.model.getTypes();
    for (final BusinessClass clazz : _types) {
      StringConcatenation _daoInterfaceBase = this.daoInterfaceBaes.daoInterfaceBase(clazz);
      InputOutput.<StringConcatenation>println(_daoInterfaceBase);
    }
  }
}